***Author: Clemens Noelke

noi di in yellow "EHTrtVars_qtrs: " in green _col(20) "syntax, " in yellow "  Creates treatment variables for event history models in quarters."

cap program drop EHTrtVars_qtrs
program define EHTrtVars_qtrs, rclass
syntax, PREFIX(string) TRTVAR(string) OMIT(string) TIMEVAR(string)

qui tab `timevar', gen(___d)
forval vl = 1/`r(r)' {
	local lbl : variable label ___d`vl'
	local lbl = real(subinstr("`lbl'","`timevar'== ","",.))
	local lbl = string(`lbl')
	local lbl = subinstr("`lbl'","-","q",.)
	if "`lbl'"!="`omit'" {	
		qui gen T_`lbl'=___d`vl'*`trtvar'
		local trtvars "`trtvars' `trtvar'_`lbl'"
	}
	macro drop _lbl
}
drop ___d*

return local trtvars "`trtvars'"

end

exit
